package cn.zhx.xa.system.controller;

import cn.zhx.xa.model.entity.SysMenu;
import cn.zhx.xa.model.vo.common.Result;
import cn.zhx.xa.model.vo.common.ResultCodeEnum;
import cn.zhx.xa.model.vo.menu.SysMenuSearchVo;
import cn.zhx.xa.system.service.SysMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value="/api/system/menu")
@Tag(name = "菜单管理")
public class SysMenuController {
   
   @Resource
   private SysMenuService sysMenuService;

   @GetMapping("/auth/findNodes")
   @Operation(summary = "查询菜单")
   public Result<List<SysMenuSearchVo>> findNodes() {
      List<SysMenuSearchVo> list = sysMenuService.findNodes();
      return Result.build(list , ResultCodeEnum.SUCCESS) ;
   }

   @PostMapping("/auth/save")
   @Operation(summary = "新增菜单")
   public Result save(@RequestBody SysMenu sysMenu) {
      sysMenuService.save(sysMenu);
      return Result.build(null , ResultCodeEnum.SUCCESS) ;
   }

   @PutMapping("/auth/updateById")
   @Operation(summary = "修改菜单")
   public Result updateById(@RequestBody SysMenu sysMenu) {
      sysMenuService.updateById(sysMenu);
      return Result.build(null , ResultCodeEnum.SUCCESS) ;
   }

   @DeleteMapping("/auth/removeById/{id}")
   @Operation(summary = "删除菜单")
   public Result removeById(@PathVariable Long id) {
      sysMenuService.removeById(id);
      return Result.build(null , ResultCodeEnum.SUCCESS) ;
   }

}